thread MAIN
  name "EmptyMap"

  var
    playerHandle: GTA.Player
    playerPed: GTA.Ped
    heliHash: GTA.Hash
    franklinHash: GTA.Hash
    hasModelLoaded: bool
    helicopter: GTA.Vehicle
  end

  // Change player to Franklin
  @franklinHash = MISC.GET_HASH_KEY("player_one")
  STREAMING.REQUEST_MODEL(@franklinHash)

  :CheckModelLoaded_Franklin
  wait locked
  @hasModelLoaded = STREAMING.HAS_MODEL_LOADED(@franklinHash)
  if
    @hasModelLoaded != false
  jump_if_false #CheckModelLoaded_Franklin

  @playerHandle = PLAYER.GET_PLAYER_INDEX()
  PLAYER.SET_PLAYER_MODEL(@playerHandle, @franklinHash)
  @playerPed = PLAYER.GET_PLAYER_PED(@playerHandle)
  PED.SET_PED_COMPONENT_VARIATION(@playerPed, 3, 13, 1, 0)
  PED.SET_PED_COMPONENT_VARIATION(@playerPed, 4, 22, 5, 0)
  PED.SET_PED_COMPONENT_VARIATION(@playerPed, 6, 11, 0, 0)
  STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(@franklinHash)
  
  // Create a helicopter, and put the player in it
  :PutPlayerInHelicopter
  // NOTE: we need to query palyer handles again, as the handles may be invalid after death
  @playerHandle = PLAYER.GET_PLAYER_INDEX()
  @playerPed = PLAYER.GET_PLAYER_PED(@playerHandle)

  @heliHash = MISC.GET_HASH_KEY("buzzard")
  STREAMING.REQUEST_MODEL(@heliHash)

  :CheckModelLoaded_Helicopter
  wait locked
  @hasModelLoaded = STREAMING.HAS_MODEL_LOADED(@heliHash)
  if
    @hasModelLoaded != false
  jump_if_false #CheckModelLoaded_Helicopter
  @helicopter = VEHICLE.CREATE_VEHICLE(@heliHash, 00., 0.0, 250.0, 0.0, false, false)

  PED.SET_PED_INTO_VEHICLE(@playerPed, @helicopter, -1)
  ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(@helicopter)
  STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(@heliHash)

  // Upon death / arrest, the palyer will get transported into a helicopter again...
  var
    dead: bool
  end

  :CheckPlayerDead
  wait 1000
  // It is a good idea... (would be required anyway, if we were to add the Save Game feature...)
  @playerHandle = PLAYER.GET_PLAYER_INDEX()
  @dead = PLAYER.IS_PLAYER_DEAD(@playerHandle)
  if
    @dead != false
  jump_if_false #CheckPlayerBusted
  jump #WaitPlayerResurrect

  :CheckPlayerBusted
  @dead = PLAYER.IS_PLAYER_BEING_ARRESTED(@playerHandle, false)
  if
    @dead != false
  jump_if_false #CheckPlayerDead

  :WaitPlayerResurrect
  wait 0
  @dead = PLAYER.IS_PLAYER_DEAD(@playerHandle)
  if
    @dead == false
  jump_if_false #WaitPlayerResurrect
  @dead = PLAYER.IS_PLAYER_BEING_ARRESTED(@playerHandle, false)
  if
    @dead == false
  jump_if_false #WaitPlayerResurrect
  wait 1000
  jump #PutPlayerInHelicopter
end

